package 力扣._228_汇总区间;

import java.util.LinkedList;
import java.util.List;

public class Solution {
    public List<String> summaryRanges(int[] nums) {
        List<String> list = new LinkedList<>();
        int begin = 0, i = 0;
        while (i < nums.length) {
            begin = nums[i];    //起始
            //向右找到第一个不连续的
            while (i + 1 < nums.length && nums[i] + 1 == nums[i + 1]) i++;
            if (begin == nums[i])
                list.add(String.valueOf(begin));
            else
                list.add(begin + "->" + nums[i]);
            i++;
        }
        return list;
    }
}
